import { useSelector } from "react-redux";
import { Navigate } from "react-router-dom"

// 路由权限实现
// 封装高阶组件  若未登录，没有token则跳转登录页面
const AuthRoute = ({ children }) => {
    const userId = useSelector(state => state.user.userInfo.id)
    if (userId) {
        return <>{ children }</>
    } else {
        return <Navigate to='/login' replace></Navigate>
    }
}

export default AuthRoute
